package com.wang.controller;

import com.aaa.entity.BAppeal;
import com.aaa.entity.BBusinessInfo;
import com.aaa.vo.FormData;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.org.apache.bcel.internal.generic.DADD;
import com.wang.entity.EmpVo;
import com.wang.mapper.BAppealMapper;
import com.wang.service.BAppealService;
import com.wang.service.BBusinessInfoService;
import com.wang.service.SysRole;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author :  DongZheng Wang
 * @PROJECT_NAME: fifth-cai-parent
 * @date :  2023-02-27 11:33http://localhost:8086/business/appeal/shensu?currentPage=1&pageSize=5
 **/

@RestController
@RequestMapping("/business")
public class BBussiessController {
    @Autowired
    private BBusinessInfoService bBusinessInfoService;
    @Autowired
    private SysRole sysRole;
    @Autowired
    private BAppealService bAppealService;

    @RequestMapping("/appeal/shensu")
    public Result appointmentAdminAll(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "5") int pageSize, @RequestBody FormData casesSearch) {
        return sysRole.appointmentAll(currentPage, pageSize, casesSearch);
    }


    @RequestMapping("/appeal/tongguo")
    public Result tonguo(String id, Integer status) {
        BBusinessInfo bBusinessInfo = new BBusinessInfo();
        BAppeal bAppeal = new BAppeal();
        Date date = new Date(System.currentTimeMillis());
        String s = date.toString();
        bAppeal.setAppealTime(s);
        LambdaUpdateWrapper<BBusinessInfo> wrapper = new LambdaUpdateWrapper();
        bBusinessInfo.setState(0);
        wrapper.set(BBusinessInfo::getState, bBusinessInfo.getState());
        wrapper.eq(BBusinessInfo::getId, id);
        bBusinessInfoService.update(wrapper);
        LambdaUpdateWrapper<BAppeal> wrapper1 = new LambdaUpdateWrapper();
        wrapper1.set(BAppeal::getStatus, status);
        wrapper1.eq(BAppeal::getBusinessId, id);
        bAppealService.update(wrapper1);

        return new Result(2000, "success");
    }

    @RequestMapping("/appeal/bohui")
    public Result bohui(String id, Integer status) {
        BAppeal bAppeal = new BAppeal();
        Date date = new Date(System.currentTimeMillis());
        String s = date.toString();
        bAppeal.setAppealTime(s);
        BBusinessInfo bBusinessInfo = new BBusinessInfo();
        LambdaUpdateWrapper<BAppeal> wrapper = new LambdaUpdateWrapper();
        wrapper.set(BAppeal::getStatus, status);
        wrapper.eq(BAppeal::getBusinessId, id);
        bAppealService.update(wrapper);
        LambdaUpdateWrapper<BBusinessInfo> wrapper1 = new LambdaUpdateWrapper();
        bBusinessInfo.setState(2);
        wrapper1.set(BBusinessInfo::getState, bBusinessInfo.getState());
        wrapper1.eq(BBusinessInfo::getId, id);
        bBusinessInfoService.update(wrapper1);
        return new Result(2000, "success");
    }

    @RequestMapping("/loadingstatus")
    public Result loadingStatus(@RequestBody BBusinessInfo bBusinessInfo) {
        LambdaUpdateWrapper<BBusinessInfo> wrapper = new LambdaUpdateWrapper<BBusinessInfo>();
        wrapper.set(BBusinessInfo::getStatus, bBusinessInfo.getStatus());
        wrapper.set(BBusinessInfo::getReason, bBusinessInfo.getReason());
        wrapper.eq(BBusinessInfo::getId, bBusinessInfo.getId());
        bBusinessInfoService.update(wrapper);
        return new Result(2000, "success");

    }
    /***
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(String id){
        bBusinessInfoService.removeById(id);
        return new Result(2000,"删除成功");
    }
}

